package com.hadoop.mr.flow;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import com.hadoop.mr.average.ScoreDriver;
import com.hadoop.mr.average.ScoreMapper;
import com.hadoop.mr.average.ScoreReducer;

public class FlowDriver {
	
	public static void main(String[] args) throws Exception {
		Configuration conf=new Configuration();
		Job job=Job.getInstance(conf);
		
		job.setJarByClass(FlowDriver.class);
		job.setMapperClass(FlowMapper.class);
		job.setReducerClass(FlowReducer.class);
		
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Flow.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputKeyClass(Flow.class);
		
		//设置分区数量
		job.setNumReduceTasks(3);
		//设置自定义的分区类，如果不设置，默认用的是HashPartitioner.class
		//记住顺序：先分区-reduce做key聚合
		job.setPartitionerClass(FlowPartitioner.class);
		
		FileInputFormat.setInputPaths(job,new Path("hdfs://192.168.234.231:9000/flow"));
		FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.234.231:9000/flow/result"));
		
		job.waitForCompletion(true);
	}

}
